import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:myshop/app/utils/screenAdapter.dart';
import '../../../../models/message_model.dart';
import '../controllers/code_login_step_one_controller.dart';
import '../../../../common/widget/logo.dart';
import '../../../../common/widget/passTextField.dart';
import '../../../../common/widget/userAgreement.dart';
import '../../../../common/widget/codeButton.dart';

class CodeLoginStepOneView extends GetView<CodeLoginStepOneController> {
  const CodeLoginStepOneView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        actions: [
          Padding(
            padding: EdgeInsets.only(right: ScreenAdapter.width(20)),
            child: Text(
              "帮助",
              style: TextStyle(
                color: Colors.black26,
                fontSize: ScreenAdapter.fontSize(28),
              ),
            ),
          ),
        ],
      ),
      body: ListView(
        padding: EdgeInsets.fromLTRB(
          ScreenAdapter.width(30),
          ScreenAdapter.height(100),
          ScreenAdapter.width(30),
          ScreenAdapter.height(30),
        ),
        children: [
          Logo(),
          SizedBox(height: ScreenAdapter.height(160)),
          PassTextField(
            controller: controller.usernameController,
            hintText: "请输入手机号码",
            onChanged: (value) {
              print("手机号码: $value");
            },
          ),
          SizedBox(height: ScreenAdapter.height(80)),
          UserAgreement(),
          SizedBox(height: ScreenAdapter.height(70)),
          CodeButton(
            textContent: "获取验证码",
            onPressed: () async {
              MessageModel messageModel = await controller.sendLoginCode();
              if (messageModel.success == true) {
                Get.offAndToNamed(
                  "/code-login-step-two",
                  arguments: {"tel": controller.usernameController.text},
                );
              } else {
                Get.snackbar("提示", "${messageModel.message}");
              }
            },
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              TextButton(
                onPressed: () {
                  Get.toNamed("/register-step-one");
                },
                child: Text("新用户注册", style: TextStyle(color: Colors.black54)),
              ),
              TextButton(
                onPressed: () {
                  Get.offAndToNamed("/pass-login");
                },
                child: Text("账号密码登录", style: TextStyle(color: Colors.black54)),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
